//
//  QSRequestHelper.h
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/23.
//  Copyright © 2020 DingC. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ResponseMessage.h"
#import "QSUploadImage.h"
#import "QSUploadVideo.h"
typedef NS_ENUM(NSUInteger, QSRequestType) {
    QSRequestTypeGet,
    QSRequestTypePost,
};

typedef NS_ENUM(NSUInteger, QSRequestContentType) {
    QSRequestContentTypeJSON,
    QSRequestContentTypeForm,
};
@interface QSRequestHelper : NSObject
/**
 * @brief ContentTypeForm的基础请求
 *
 * @param type         请求类型
 * @param headerDic    请求头
 * @param requestUrl   请求url
 * @param requestCount 请求次数
 * @param bodyDic      请求param
 * @param block        请求返回的数据
 *
 * @return NSURLSessionTask 该次请求的task 可取消请求,调用cancel方法
 */
+ (NSURLSessionTask *)executeRequestWithType:(QSRequestType)type
                                     headers:(NSMutableDictionary *)headerDic
                                  requestUrl:(NSString *)requestUrl
                                requestCount:(int)requestCount
                                 requestBody:(NSMutableDictionary *)bodyDic
                                    andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic))block;

/**
 * @brief 基础请求
 *
 * @param type         请求类型
 * @param contentType  内容格式
 * @param headerDic    请求头
 * @param requestUrl   请求url
 * @param requestCount 请求次数
 * @param bodyDic      请求param
 * @param block        请求返回的数据
 *
 * @return NSURLSessionTask 该次请求的task 可取消请求,调用cancel方法
 */
+ (NSURLSessionTask *)executeRequestWithType:(QSRequestType)type
                                 contentType:(QSRequestContentType)contentType
                                     headers:(NSMutableDictionary *)headerDic
                                  requestUrl:(NSString *)requestUrl
                                requestCount:(int)requestCount
                                 requestBody:(NSMutableDictionary *)bodyDic
                                    andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic))block;

/**
 *  @brief 上传图片(单张)
 *
 *  @param path      请求路径
 *  @param image     图片(类型是QSUploadImage)
 *  @param headerDic 请求头
 *  @param bodyDic   非文件参数 (字典) {rentInfoId : }
 */
+ (NSURLSessionTask *)uploadImageWithPath:(NSString *)path
                                  headers:(NSMutableDictionary *)headerDic
                                    image:(QSUploadImage *)image
                                   params:(NSDictionary *)bodyDic
                                 andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic))block;

/**
 *  @brief 上传图片(多张)
 *
 *  @param path      请求路径
 *  @param headerDic 请求头
 *  @param photos    图片数组(类型是QSUploadImage)
 *  @param bodyDic   非文件参数 (字典)
 */
+ (NSURLSessionTask *)uploadImageWithPath:(NSString *)path
                                  headers:(NSMutableDictionary *)headerDic
                                   photos:(NSArray<QSUploadImage *> *)photos
                                   params:(NSDictionary *)bodyDic
                                 andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic))block;

/**
 *  @brief 上传视频(多个)
 *
 *  @param path      请求路径
 *  @param headerDic 请求头
 *  @param videos    视频数组(类型是QSUploadVideo)
 *  @param bodyDic   非文件参数 (字典)
 */
+ (NSURLSessionTask *)uploadVideoWithPath:(NSString *)path
                                  headers:(NSMutableDictionary *)headerDic
                                   videos:(NSArray<QSUploadVideo *> *)videos
                                   params:(NSDictionary *)bodyDic
                                 andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic))block;


/**
* @brief 用于返回data为数组的基础请求
*
* @param type         请求类型
* @param contentType  内容格式
* @param headerDic    请求头
* @param requestUrl   请求url
* @param requestCount 请求次数
* @param bodyDic      请求param
* @param block        请求返回的数据
*
* @return NSURLSessionTask 该次请求的task 可取消请求,调用cancel方法
*/
+ (NSURLSessionTask *)executeRequestReturnArrayWithType:(QSRequestType)type
                                            contentType:(QSRequestContentType)contentType
                                                headers:(NSMutableDictionary *)headerDic
                                             requestUrl:(NSString *)requestUrl
                                           requestCount:(int)requestCount
                                            requestBody:(NSMutableDictionary *)bodyDic
                                               andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSArray *responseDataArr))block;
/// 有网YES, 无网:NO
+ (BOOL)isNetwork;
/// 手机网络:YES, 反之:NO
+ (BOOL)isWWANNetwork;
/// WiFi网络:YES, 反之:NO
+ (BOOL)isWiFiNetwork;

///  取消所有请求操作
+ (void)cancelAllRequest;
///  取消某一个url的请求
+ (void)cancelRequestWithURL:(NSString *)URL;
/// 设置请求头
+ (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
@end


